"use strict";

var fs   = require('fs');
var path = require('path');

class ImageController {
  *index(ctx){
    yield ctx.render('ImageBoard/index');
  }

  *upload(ctx){
    var filesInfo = ctx.request.body.files.image;

    var staticPath = path.resolve(__dirname, '../../static');
    var relativePath  = path.relative(staticPath, filesInfo.path);
    filesInfo.path = path.join(ctx.host, relativePath);

    ctx.body = JSON.stringify(filesInfo);
  }

  getOriginalFilePath(path){
  }

  *convert(ctx, next){
    yield next;

    if(ctx.status === 404 && ctx.path.indexOf('/upload/') !== -1){
      ctx.status = 200;
      ctx.body = 'convert';
    }
  }
}

module.exports = new ImageController();
